﻿@model RH.Web.ViewModels.UtilityModels.ListConfig
@using RH.Web.Utility;
@using RH.Web.ViewModels
@{    
	String pageTitle = "List of Saved Searches";
    ViewBag.Title = Html.GetPageTitle(pageTitle);
	//String _EditUrlFormat = Url.PrivateUrl("Edit", "SavedSearch") + "/{0}";
	///Bind SavedSearch ListConfig
	///Following ListConfig binding needs to be edited according to the query result and need.
    RH.Web.ViewModels.UtilityModels.ListConfig _ListConfig = RH.Web.ViewModels.UtilityModels.ListConfigBuilder.Build(
        @"Saved Search List {ID|Property Type|Keyword|Saved On}"
        , Model.DataSource, null);
    //Add a Delete Column
    RH.Web.ViewModels.UtilityModels.Column deleteColumn = new RH.Web.ViewModels.UtilityModels.Column("Delete",
    P =>
    {
        int id = RH.Common.DB.NullHandler.GetInt(P["ID"]);
        return MvcHtmlString.Create(String.Format("<a class=\"btn btn-warning btn-sm\" href=\"javascript:void(0);\" onclick=\"DeleteConfirm({0}, this, _DelCnfMsg);\"><i class=\"glyphicon glyphicon-remove\"></i> </a>", id));
    });
    RH.Web.ViewModels.UtilityModels.Column executeColumn = new RH.Web.ViewModels.UtilityModels.Column("Execute Search",
    P =>
    {
        int catID = RH.Common.DB.NullHandler.GetInt(P["CategoryID"]);
        String type = RH.Common.DB.NullHandler.GetBoolean(P["IsForRent"]) ? "R" : "B";
        String key = RH.Common.DB.NullHandler.GetString(P["Keyword"]);
        return MvcHtmlString.Create(String.Format("<a class=\"btn btn-default btn-sm\" href=\"{0}\"><i class=\"glyphicon glyphicon-repeat\"></i> Execute</a>",
            String.Format("/Product/Search?key={0}&type={1}&cat={2}", key, type, catID)));
    });
    _ListConfig.Columns.Add(executeColumn);
    _ListConfig.Columns.Add(deleteColumn);
    RH.Web.ViewModels.UtilityModels.ListConfig.Map(_ListConfig, Model);
      
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = SiteUserMenu.SavedSearch;
}
<div class="rh-page-heading">
    <h1>@pageTitle</h1>
    <div>
        List of Your Saved Searches
    </div>
</div>
<div class="rh-page-content">
    <div class="panel panel-success">
        <div class="panel-heading">
            <div class="pull-left"><h4>Saved Searches</h4></div>
            <div class="pull-right">@*<a class="btn btn-success" href="@Url.PrivateUrl("Edit", "SavedSearch")"><i class="glyphicon glyphicon-plus"></i> Add New SavedSearch</a>*@</div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">            
            @Html.Partial("_DataTableList", Model)
        </div>
    </div>
    @if (Model.Pager != null)
    {
        @Html.Partial("_Pager", Model.Pager)
    }
</div>

@{
    ModalViewModel deleteConfirm = new ModalViewModel("deleteConfirm", "Confirm", String.Format("DeleteEntity('{0}', 'Saved Search Deleted Successfully.', 'Sorry! we were not able to delete this Saved Search.');", Url.SiteUserUrl("Delete", "SavedSearch")));
}
@Html.Partial("_Modal", deleteConfirm)

@section JavaScriptPlaceHolder{
    <script language="javascript" type="text/javascript">
        var _DelCnfMsg = 'Are your sure you want to delete this Saved Search?';
    </script>
}    


